home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Sprite 1984 - 1993
/
Sprite 1984 - 1993.iso
/
src
/
cmds
/
oldwish
/
RCS
/
wishUtils.c,v
< prev
Wrap
Text File
|
1990-01-19
|
8KB
|
379 lines
head 1.4;
branch ;
access ;
symbols ;
locks mgbaker:1.4; strict;
comment @ * @;
1.4
date 89.01.11.11.58.50; author mlgray; state Exp;
branches ;
next 1.3;
1.3
date 88.11.03.19.45.34; author mlgray; state Exp;
branches ;
next 1.2;
1.2
date 88.11.02.14.51.05; author mlgray; state Exp;
branches ;
next 1.1;
1.1
date 88.10.03.12.48.54; author mlgray; state Exp;
branches ;
next ;
desc
@X11: works pretty much now.
@
1.4
log
@Temporary checkin
@
text
@/*
* wishUtils.c --
*
* Useful stuff -- delivering error msgs, etc.
*
* Copyright 1987 Regents of the University of California
* All rights reserved.
* Permission to use, copy, modify, and distribute this
* software and its documentation for any purpose and without
* fee is hereby granted, provided that the above copyright
* notice appear in all copies. The University of California
* makes no representations about the suitability of this
* software for any purpose. It is provided "as is" without
* express or implied warranty.
*/
#ifndef lint
static char rcsid[] = "$Header: /a/newcmds/wish/RCS/wishUtils.c,v 1.3 88/11/03 19:45:34 mlgray Exp Locker: mlgray $ SPRITE (Berkeley)";
#endif not lint
#include "string.h"
#include "sx.h"
#include "util.h"
#include "wishInt.h"
static WishWindow *menuWindow = NULL;
/*
*----------------------------------------------------------------------
*
* WishCvtToPrintable --
*
* Given a keystroke binding that may contain control characters
* and/or meta characters, this routine produces a printable version
* of the string.
*
* Results:
* Up to length characters are stored at *result (including the
* terminating NULL character).
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
void
WishCvtToPrintable(string, length, result)
char *string; /* Binding string to be converted. */
int length; /* No. of bytes available at result. */
char *result; /* Where to store printable form. */
{
int chunkSize;
char chunk[20];
char *p;
/*
* Process the input string one character at a time to do the
* conversion.
*/
p = result;
for ( ; *string != 0; string++) {
int i;
/*
* Figure out how to represent this particular character.
*/
i = *string & 0377;
if (i <= 040) {
if (i == 033) {
strcpy(chunk, "ESC");
} else if (i == '\n') {
strcpy(chunk, "RET");
} else if (i == '\t') {
strcpy(chunk, "TAB");
} else if (i == ' ') {
strcpy(chunk, "SPACE");
} else {
chunk[0] = 'C';
chunk[1] = '-';
chunk[2] = i - 1 + 'a';
chunk[3] = 0;
}
} else if (i < 0177) {
chunk[0] = i;
chunk[1] = 0;
} else if (i == 0177) {
strcpy(chunk, "DEL");
} else if ((i > 0240) && (i < 0377)) {
chunk[0] = 'M';
chunk[1] = '-';
chunk[2] = i & 0177;
chunk[3] = 0;
} else {
sprintf(chunk, "%#x", i);
}
/*
* Add this chunk onto the result string (if it fits), with a
* preceding space if this isn't the first chunk.
*/
if (p != result) {
if (length < 1) {
break;
}
*p = ' ';
p++;
length--;
}
chunkSize = strlen(chunk);
if (length < chunkSize) {
strncpy(p, chunk, length);
p += length;
length = 0;
break;
} else {
strcpy(p, chunk);
p += chunkSize;
length -= chunkSize;
}
}
if (length == 0) {
p--;
}
*p = 0;
}
/*
*----------------------------------------------------------------------
*
* WishMenuProc --
*
* This procedure is invoked whenver a menu command is invoked
* in an wish window. It now forces the interpreter to be the
* one for the central display window. Should I have a separate one
* for the menus?
*
* Results:
* None.
*
* Side effects:
* The command.
*
*----------------------------------------------------------------------
*/
void
WishMenuProc(command)
char *command; /* Command string */
{
Window w;
WishWindow *aWindow;
if (menuWindow == NULL) {
return;
}
w = menuWindow->surroundingWindow;
if (XFindContext(wishDisplay, w, wishWindowContext, (caddr_t) &aWindow)
!= 0) {
Sx_Panic(wishDisplay, "Wish didn't recognize given window.");
}
(void) WishDoCmd(aWindow, command);
#ifdef NOTDEF
/* could have destroyed window stuff again... */
#endif NOTDEF
}
/*
*----------------------------------------------------------------------
*
* WishMakeMenu --
*
* Duplicate the command strings in an array of menu entries, then
* invoke Sx to create a menu. It's needed in order to make sure
* that all of the command strings in all menus, even the initial
* default menus, are dynamically allocated.
*
* Results:
* None.
*
* Side effects:
* Memory gets allocated, and a menu gets created.
*
*----------------------------------------------------------------------
*/
void
WishMakeMenu(aWindow, name, size, info)
register WishWindow *aWindow;/* Window in which to create menu. */
char *name; /* Name of menu. */
int size; /* Number of entries in menu. */
Sx_MenuEntry info[]; /* Menu inforamtion. */
{
Sx_MenuEntry entries[SX_MAX_MENU_ENTRIES];
int i;
for (i = 0; i < size; i++) {
entries[i] = info[i];
entries[i].clientData = (ClientData) Util_Strcpy((char *) NULL,
(char *) info[i].clientData);
}
(void) Sx_MenuCreate(wishDisplay, aWindow->menuBar, name, size, entries,
aWindow->fontPtr, aWindow->menuForeground,
aWindow->menuBackground);
}
/*
*----------------------------------------------------------------------
*
* WishMenuEntryProc --
*
* This procedure is invoked by the Sx dispatcher whenever the
* mouse enters a menu bar window.
*
* Results:
* None.
*
* Side effects:
* The variable menuWindow is updated to keep track of which
* Wish window the cursor's in, so that we'll know when a menu
* entry gets invoked.
*
*----------------------------------------------------------------------
*/
void
WishMenuEntryProc(aWindow, eventPtr)
WishWindow *aWindow; /* Window whose menu bar was just
* entered. */
XEnterWindowEvent *eventPtr; /* Event describing window entry. */
{
#ifdef NOTDEF
if (eventPtr->subwindow != NULL) {
return;
}
#endif /* NOTDEF */
menuWindow = aWindow;
}
@
1.3
log
@Fixed many bugs - notifiers no longer trash the display.
@
text
@d18 1
a18 1
static char rcsid[] = "$Header: /a/newcmds/wish/RCS/wishUtils.c,v 1.2 88/11/02 14:51:05 mlgray Exp Locker: mlgray $ SPRITE (Berkeley)";
@
1.2
log
@fsflat changed to wish
@
text
@d18 1
a18 1
static char rcsid[] = "$Header: wishUtils.c,v 1.1 88/10/03 12:48:54 mlgray Exp $ SPRITE (Berkeley)";
a232 1
@
1.1
log
@Initial revision
@
text
@d2 1
a2 1
* fsflatUtils.c --
d18 1
a18 1
static char rcsid[] = "$Header: fsflatUtils.c,v 1.3 88/06/05 19:56:06 mlgray Exp $ SPRITE (Berkeley)";
d25 1
a25 1
#include "fsflatInt.h"
d27 1
a27 1
static FsflatWindow *menuWindow = NULL;
d33 1
a33 1
* FsflatCvtToPrintable --
d49 1
a49 1
FsflatCvtToPrintable(string, length, result)
d138 1
a138 1
* FsflatMenuProc --
d141 1
a141 1
* in an fsflat window. It now forces the interpreter to be the
d154 1
a154 1
FsflatMenuProc(command)
d158 1
a158 1
FsflatWindow *aWindow;
d164 1
a164 1
if (XFindContext(fsflatDisplay, w, fsflatWindowContext, (caddr_t) &aWindow)
d166 1
a166 1
Sx_Panic(fsflatDisplay, "Fsflat didn't recognize given window.");
d169 1
a169 1
(void) FsflatDoCmd(aWindow, command);
d180 1
a180 1
* FsflatMakeMenu --
d196 2
a197 2
FsflatMakeMenu(aWindow, name, size, info)
register FsflatWindow *aWindow;/* Window in which to create menu. */
d210 1
a210 1
(void) Sx_MenuCreate(fsflatDisplay, aWindow->menuBar, name, size, entries,
d218 1
a218 1
* FsflatMenuEntryProc --
d228 1
a228 1
* Fsflat window the cursor's in, so that we'll know when a menu
d235 2
a236 2
FsflatMenuEntryProc(aWindow, eventPtr)
FsflatWindow *aWindow; /* Window whose menu bar was just
d240 1
d244 1
@